﻿#ifndef PLCWORKER_H
#define PLCWORKER_H

#include <QObject>
#include "Common/common.h"
#include <QtSerialPort>
#include <QSerialPortInfo>
class PlcWorker : public QObject
{
    Q_OBJECT
public:
    explicit PlcWorker(QObject *parent = nullptr);
    ~PlcWorker();
    bool m_bPlcConnect;
    PlcInfo m_coPlcInfo;
    QSerialPort *m_serialPort;
    void sendInfo(QByteArray sendBuf);

    void readPlcInfo(SIG_PLC nSig);
    void writePlcInfo(SIG_PLC nSig, int nIndex);
    void writePlcInfo(SIG_PLC nSig, float nIndex);

    void splitFloat(float fIndex,int& nIndex1,int& nIndex2);
    int m_nSig = 0;
    QByteArray byReadBuf;
    bool m_bReceive = false;




    int m_nENCODER = 0;
    int m_nMOTOR1_REV = 0;
    int m_nPCCD_1 = 0;
    int m_nPCCD_2 = 0;
    int m_nPCCD_3 = 0;
    int m_nPCCD_4 = 0;
    int m_nPCCD_5 = 0;
    int m_nPCCD_6 = 0;
    int m_nPCCD_7 = 0;
    int m_nPCCD_8 = 0;

    int m_nMOTOR_NG1 = 0;
    int m_nMOTOR_NG2 = 0;
    int m_nMOTOR_NG3 = 0;
    int m_nMOTOR_NG4 = 0;
    int m_nMOTOR_NG5 = 0;
    int m_nMOTOR_NG6 = 0;

    int m_nBLOW_TIME = 0;

    int m_nFALL_TIME = 0;
    int m_nWARN_TIME = 0;
    int m_nSTOP_TIME = 0;

    int m_nINCODERA = 0;
    int m_nINCODERB = 0;


    int m_nTOUCH_CCD1A = 0;
    int m_nTOUCH_CCD1B = 0;
    int m_nTOUCH_CCD2A = 0;
    int m_nTOUCH_CCD2B = 0;
    int m_nTOUCH_CCD3A = 0;
    int m_nTOUCH_CCD3B = 0;
    int m_nTOUCH_CCD4A = 0;
    int m_nTOUCH_CCD4B = 0;
    int m_nTOUCH_CCD5A = 0;
    int m_nTOUCH_CCD5B = 0;
    int m_nTOUCH_CCD6A = 0;
    int m_nTOUCH_CCD6B = 0;


signals:
public slots :
    void receiveInfo();
    void Initialize();
    void start();
};

#endif // PLCWORKER_H
